home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch03 / fix.c < prev    next >
C/C++ Source or Header  |  1993-06-11  |  3KB  |  115 lines

  1. /****************************************************************
  2. * FILE:    fix.c
  3. * DESC:    This program inputs a list of pictures, creates a best
  4. *        fit palette, remaps the pictures, and writes them out.
  5. * HISTORY:    Created     1/13/1993
  6. * LAST CHANGED: 3/10/1993
  7. *    Copyright (c) 1993 by Scott Anderson
  8. *
  9. ****************************************************************/
  10.  
  11. /* ----------------------INCLUDES----------------------------- */
  12.  
  13. #include <conio.h>
  14. #include <stdio.h>
  15. #include <io.h>
  16. #include <math.h>
  17. #include <graph.h>
  18. #include <malloc.h>
  19. #include <memory.h>
  20. #include <string.h>
  21.  
  22. #include "define.h"
  23.  
  24. /* ----------------------EXTERNALS---------------------------- */
  25.  
  26. extern LINKED_LIST    *rootSequence(int argc, char *argv[]);
  27.  
  28. /**** color routines ****/
  29. extern int        closestColor(int r, int g, int b, PALETTE *pal);
  30. extern void        collapseColors(PALETTE *palPtr);
  31. extern int        mergePalette(PICTURE *pic);
  32. extern int        remapPicture(PICTURE *picPtr, PALETTE *palPtr);
  33.  
  34. /**** line routines ****/
  35. extern int        getLine(int *argx1, int *argy1,
  36.                         int *argx2, int *argy2);
  37. extern int        movePoint();
  38. extern int        setLength(LINE *line);
  39.  
  40. /**** other variables ****/ 
  41.  
  42. extern char        *OutFilename;
  43.  
  44. /* set from last picture loaded */
  45. extern int        Xmin, Ymin, Xmax, Ymax;
  46.  
  47. /* ----------------------GLOBAL DATA-------------------------- */
  48.  
  49. PICTURE *Src;        /* source & destination picture pointers */
  50.  
  51. /***** variables used to compute intermediate images ****/
  52.  
  53. /* number of colors in tweened image before reduction*/
  54. extern int     Ncolors;
  55. /* r, g, b frequency counter array */
  56. extern unsigned int far Freq[MAX_COMP][MAX_COMP][MAX_COMP];
  57.  
  58. /* tweened images red, grn, and blu components*/
  59. extern unsigned char far Red[MAX_WIDE][MAX_TALL];
  60. extern unsigned char far Grn[MAX_WIDE][MAX_TALL];
  61. extern unsigned char far Blu[MAX_WIDE][MAX_TALL];
  62.  
  63. extern PALETTE TweenPal;            /* resulting palette */
  64.  
  65. /*****************************************************************
  66. * FUNC: main (int argc, char *argv[])
  67. * DESC: Read in a list of filenames to load, change their palettes
  68. *        to the best-fit palette, and write them out.
  69. *****************************************************************/
  70.  
  71. main (int argc, char *argv[])
  72. {
  73.     int        file;
  74.     LINKED_LIST *pcxList, *pcxListHead;
  75.  
  76.     /* load the pcx file if one is given */
  77.     if (argc < 3) {
  78.         printf("Usage: fix <infile> <outfile>\n\n");
  79.         printf("Where: <infile>  is the input sequence name\n");
  80.         printf("       <outfile> is the output sequence name\n");
  81.         exit(0);
  82.     }
  83.     OutFilename = argv[argc-1];
  84.     initFreq();
  85.     pcxListHead =  rootSequence(argc-1, argv);
  86.     for (pcxList = pcxListHead; pcxList; pcxList=pcxList->next) {
  87.         printf("Loading the file %s\n", pcxList->str);
  88.         Src = loadPicture(pcxList->str);
  89.         if (Src == NULL)
  90.             quit(MEMORY_ERR, "");
  91.  
  92.         mergePalette(Src);
  93.         freePicture(Src);
  94.     }
  95.     collapseColors(&TweenPal);
  96.     setGraphicsMode();
  97.     setPalette(&TweenPal);
  98.  
  99.     for (pcxList = pcxListHead; pcxList; pcxList=pcxList->next) {
  100.         Src = loadPicture(pcxList->str);
  101.         if (Src == NULL)
  102.             quit(MEMORY_ERR, "");
  103.  
  104.         remapPicture(Src, &TweenPal);
  105.         displayNoPal(Src);
  106.         saveScreen(&TweenPal);
  107.         freePicture(Src);
  108.     }
  109.     setTextMode();
  110. }
  111.  
  112.